using Godot;
using System.Collections;
using System.Collections.Generic;
using Box.GameCore;
using Box.Base;

namespace Box.DefaultSandbox {
    public enum SandboxRegionStatus {
        Loading,//加载中，表示正在生成或者读取
        Unloading,//卸载中，表示正在写入存档以及从内存中删除
        Running,//运行中，表示已加载
        Unknown,
    }

    public class SandboxRegion : IStorage 
    {
        [Storage]
        protected int _x;
        [Storage]
        protected int _y;
        [Storage]
        protected Hashtable _tilesets = new Hashtable();
        [Storage]
        protected ArrayList _entities = new ArrayList();
        [Storage]
        protected int[][] Layers;


        public SandboxRegionStatus Status = SandboxRegionStatus.Unknown;
        public int X {get ;set ;}
        public int Y {get;set;}
        public Dictionary<int,string> TilesetNameIndexses = new Dictionary<int, string>();
        //TilesetNameIndexses的反向索引，用于获取Tileset对应的数字ID
        protected Dictionary<string,int> TilesetNameIndexses2 = new Dictionary<string,int>();
        public Dictionary<IEntity, IEntity> Entities {get;} = new Dictionary<IEntity, IEntity>();

        public Dictionary<int, IBlock> TileInstances {get;} = new Dictionary<int, IBlock>();

        public void onStorageWriteReady() {
            _tilesets.Clear();
            _entities.Clear();

            _x = X;
            _y = Y;

            foreach(IEntity entity in Entities.Values) {
                if(entity is IStorage) {
                    _entities.Add(entity);
                }
            }
        }
    }
}